package com.rd.student.ruanjian.class4.lichunquan.Text02;

import java.util.*;

public class Test07 {
    //省会
    public static void main(String[] args) {
        HashMap<String , Integer>  hashMap = new HashMap();
        LinkedHashMap<String,String> linkedHashMap =new LinkedHashMap<>();
        linkedHashMap.put("哈尔滨","黑龙江省");
        linkedHashMap.put("大庆","黑龙江省");
        linkedHashMap.put("绥化","黑龙江省");
        linkedHashMap.put("齐齐哈尔","黑龙江省");
        linkedHashMap.put("沈阳","黑龙江省");
        linkedHashMap.put("杭州","浙江省");
        linkedHashMap.put("宁波","浙江省");
        linkedHashMap.put("南昌","江西省");
        linkedHashMap.put("广州","广东省");
        linkedHashMap.put("福州","福建省");
        linkedHashMap.put("厦门","福建省");
        //建立hashmap
        int count = 1;
        Iterator iterator01 =linkedHashMap.keySet().iterator();
        while(iterator01.hasNext()){
            String str =(String) iterator01.next();
            String l_value = linkedHashMap.get(str);
            if(hashMap.containsKey(l_value)){
                //修改count
                hashMap.put(l_value,hashMap.get(l_value)+1);
            }else{
                //添加省份
                hashMap.put(l_value,count);
            }
        }
        while(true){
            System.out.println("=======================");
            System.out.println("功能 1: 查看隶属于哪个省");
            System.out.println("功能 2: 退出");
            System.out.println("功能 3: 查看目前含有的城市");
            System.out.println("功能 4: 查看目前含有的省份");
            System.out.println("功能 5: 查看各省份包含城市");
            System.out.println("功能 6: 查看各省份人数");
            System.out.println("=======================");
            System.out.println();
            Scanner sc = new Scanner(System.in);
            switch (sc.nextInt()){
                case 1:
                    System.out.println("输入要查看的城市");
                    System.out.println("格式如:哈尔滨");
                    //可以添加字符串检索（模糊查询）
                    String str1 = sc.next();
                    System.out.println("=======================");
                    for (int i = 0; i < linkedHashMap.size(); i++) {
                        if(linkedHashMap.containsKey(str1)){
                            System.out.println(linkedHashMap.get(str1));
                            break;
                        }else{
                            System.out.println("未找到该城市！");
                        }
                    }
                    System.out.println("=======================");
                    break;
                case 2:
                    return;
                case 3:
                    int i = 1;
                    Iterator iterator =linkedHashMap.keySet().iterator();
                    StringBuilder stringBuilder01 = new StringBuilder();
                    while(iterator.hasNext()) {
                        String str = (String) iterator.next();
                            stringBuilder01.append(i++ +". "+str+"\n");
                    }
                    System.out.println(stringBuilder01);
                    break;
                case 4:
                    System.out.println("=======================");
                    System.out.println(hashMap.keySet());
                    System.out.println("=======================");
                    break;
                case 5:
                    //查看各省份包含城市
                    int j = 1;
                    System.out.println("输入要查看省份");
                    String sc_next = sc.next();
                    Iterator iterator02 =linkedHashMap.keySet().iterator();
                    System.out.println("=======================");
                    while(iterator02.hasNext()){
                        String l_key =(String) iterator02.next();
                        String l_value = linkedHashMap.get(l_key);
                        if(sc_next.equals(l_value)){
                            System.out.println(j++ +". "+ l_key);
                        }
                    }
                    System.out.println("=======================");
                    break;
                case 6:
                    //查看各省份人数

                    System.out.println(hashMap);
                    break;
                default:
                    System.out.println("输入有误");
            }


        }

    }

}
